package com.hospital.payment.module.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.common.enums.RoleType;
import com.hospital.common.pojo.TPatientInfo;
import com.hospital.common.pojo.TUser;
import com.hospital.payment.module.exception.UserServiceException;
import com.hospital.payment.module.exception.enums.UserExpCode;
import com.hospital.payment.module.mapper.TUserMapper;
import com.hospital.payment.module.service.TPatientInfoService;
import com.hospital.payment.module.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements TUserService{
    @Autowired
    private TUserMapper tUserMapper;
    @Autowired
    private TPatientInfoService tPatientInfoService;
    @Override
    public Boolean checkMedicalCard(Long patientId) {
        TUser user = tUserMapper.selectById(patientId);
        if(ObjectUtils.isEmpty(user)){
            throw new UserServiceException(UserExpCode.USER_NOT_EXIST);
        }
        if(!user.getRole().equals(RoleType.PATIENT.value)){
            throw new UserServiceException(UserExpCode.INVALID_ROLE);
        }
        TPatientInfo patientInfo = tPatientInfoService.getById(user.getInfoId());
        if(ObjectUtils.isEmpty(patientInfo)){
            throw new UserServiceException(UserExpCode.USER_INFO_NOT_EXIST);
        }
        return !ObjectUtils.isEmpty(patientInfo.getMedicalCard());
    }
}
